package dao

import (
	"gin-study/pkg/orm"
	"gorm.io/gorm"
)

var Order *order

type order struct {
	*gorm.DB
}

func init() {
	Order = &order{
		DB: orm.DB(),
	}
}

func (o *order) ScopeUserId(userId uint) Scope {
	return func(db *gorm.DB) *gorm.DB {
		if userId != 0 {
			db.Where("user_id", userId)
		}
		return db
	}
}

func (o *order) ScopeStatus(status string) Scope {
	return func(db *gorm.DB) *gorm.DB {
		if len(status) > 0 {
			db.Where("status", status)
		}
		return db
	}
}

func (o *order) ScopeOrderSn(orderSn string) Scope {
	return func(db *gorm.DB) *gorm.DB {
		if len(orderSn) > 0 {
			db.Where("order_sn", orderSn)
		}
		return db
	}
}
